﻿using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;
using System;



namespace ImageEnhancer

{

    public class ImageEnhancerCustomField : SPFieldText

    {

        public ImageEnhancerCustomField(SPFieldCollection fields, string fieldName)

            : base(fields, fieldName)

        { }// }
        
 

        public ImageEnhancerCustomField(SPFieldCollection fields, string typeName, string displayName)

            : base(fields, typeName, displayName)

        { }

 

        public override BaseFieldControl FieldRenderingControl

        {

            get

            {
                SPContext.Current.List.EnableAttachments = false;

                BaseFieldControl fieldControl = new ImageEnhancerControl();

                fieldControl.FieldName = this.InternalName;
                
                return fieldControl;
                
            }

        }

 

        public override string GetValidatedString(object value)

        {
            
            return value.ToString().ToUpper();// +" " + value.ToString().Split('%')[0];
            
        }
        ~ImageEnhancerCustomField() {
            try {
                /////SPContext.Current.List.EnableAttachments = true;
            }
            catch(Exception e ){
                //
            }
        }
        public override void OnAdded(SPAddFieldOptions op)
        {
            SPContext.Current.List.EnableAttachments = false;
            base.OnAdded(op);


        }
        public virtual void FieldAdded(SPListEventProperties properties) {
            //SPContext.Current.List.EnableAttachments = true;
            SPContext.Current.List.EnableAttachments = false;
        }


    }

}

